<template>
  <div class="list-content">
    <Row>
      <Col span="12">
          <DatePicker type="date" placeholder="请选择查询日期" format="yyyy-MM-dd" @on-change="onChange" style="width: 200px"></DatePicker>
      </Col>
    </Row>
    <Row type="flex" justify="start" class="code-row-bg" v-if="list.length !== 0">
      <div v-for="item in list" :key="item.cveid" class="list-cve">
        <Card>
          <div class="list-cveid">
            <Button type="primary" @click="toLink(item.url)">{{ item.cveid }}</Button>
          </div>
          <div class="list-info">
            <div class="list-half">
              公司：
              <Button shape="circle" size="small">{{ item.company }}</Button>
            </div>
            <div class="list-half">
              发布时间：
              <Button shape="circle" size="small">{{ item.createdate }}</Button>
            </div>
          </div>
          <Collapse v-model="cveList[item.cveid]">
            <Panel name="1">
              描述
              <p slot="content">{{ item.description }}</p>
            </Panel>
          </Collapse>
        </Card>
      </div>
    </Row>
    <div class="list-empty" v-else>暂无数据</div>
    <BackTop :height="100"></BackTop>
  </div>
</template>
<script>
export default {
  name: 'DailyCVE',
  data () {
    return {
      // list: [{'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2017-15640', 'cveid': 'CVE-2017-15640', 'company': 'MITRE Corporation', 'createdate': '20171019', 'description': 'app/sections/user-menu.php in phpIPAM before 1.3.1 has XSS via the ipparameter.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10126', 'cveid': 'CVE-2018-10126', 'company': 'MITRE Corporation', 'createdate': '20180416', 'description': 'LibTIFF 4.0.9 has a NULL pointer dereference in the jpeg_fdct_16x16function in jfdctint.c.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10254', 'cveid': 'CVE-2018-10254', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'Netwide Assembler (NASM) 2.13 has a stack-based buffer over-read in thedisasm function of the disasm/disasm.c file. Remote attackers couldleverage this vulnerability to cause a denial of service or possiblyhave unspecified other impact via a crafted ELF file.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10265', 'cveid': 'CVE-2018-10265', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'An issue was discovered in HongCMS v3.0.0. There is a CSRFvulnerability that can add an administrator account via theadmin/index.php/users/save URI.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10266', 'cveid': 'CVE-2018-10266', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'BEESCMS 4.0 has a CSRF vulnerability to add an administrator accountvia the admin/admin_admin.php?nav=list_admin_user&admin_p_nav=user URI.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10267', 'cveid': 'CVE-2018-10267', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'WTCMS 1.0 has a CSRF vulnerability to add an administrator account viathe index.php?admin&m=user&a=add_post URI.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10268', 'cveid': 'CVE-2018-10268', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'An issue was discovered in FastAdmin V1.0.0.20180417_beta. There is XSSvia the application\\api\\controller\\User.php avatar parameter.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10283', 'cveid': 'CVE-2018-10283', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'CliqueMania loja virtual 14 has SQL Injection via the patch/remote.phpid parameter in a recomendar action.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10284', 'cveid': 'CVE-2018-10284', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'Adaltech G-Ticket v70 EME104 has SQL Injection via themobile-loja/mensagem.asp eve_cod parameter.'}, {'url': 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-10289', 'cveid': 'CVE-2018-10289', 'company': 'MITRE Corporation', 'createdate': '20180421', 'description': 'In MuPDF 1.13.0, there is an infinite loop in the fz_skip_spacefunction of the pdf/pdf-xref.c file. A remote adversary could leveragethis vulnerability to cause a denial of service via a crafted pdf file.'}],
      list: [],
      cveList: []
    }
  },
  mounted () {
    console.log(this.list)
    this.getData()
  },
  methods: {
    onChange (date) {
      this.getData(date)
    },
    getData (date) {
      const self = this
      const now = new Date()
      const d = new Date(now.setDate(now.getDate() - 1))
      const yesterday = `${d.getFullYear()}-${('0' + (d.getMonth() + 1)).slice(-2)}-${d.getDate()}`
      const query = date || yesterday
      this.$axios.get('/api/search_today', {
        params: {
          'query_date': query
        }
      }).then(function (result) {
        if (result.data.code === 0) {
          self.list = []
        } else {
          let origin = result.data.data
          self.list = origin
          console.log(origin)
          origin.forEach(value => {
            self.cveList[value.cveid] = ''
          })
        }
      }).catch(err => {
        self.list = []
        self.cveList = []
        // this.$Message.error(JSON.stringify(err))
        console.log(err)
      })
    },
    toLink (url) {
      window.open(url)
    }
  }
}
</script>
<style scoped>
  .list-cve {
    /* display: inline; */
    width: 50%;
    margin: 10px auto;
    padding-right: 10px;
  }
  .list-info {
    display: flex;
    margin: 10px auto;
  }
  .list-half {
    flex: 1;
  }
  .list-desc {
    margin: 5px auto;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  .list-empty {
    margin: 200px auto;
    text-align: center;
  }
</style>
